package com.example.confessionwall.controller;

import com.example.confessionwall.model.Message;
import com.example.confessionwall.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    MessageService messageService;
    @RequestMapping("/setMessage")
    public Boolean setMessage(Message message){
        if (!StringUtils.hasLength(message.getFromUser()) ||
                !StringUtils.hasLength(message.getToUser()) ||
                !StringUtils.hasLength(message.getMessage())) {

            return false;
        }
        messageService.setMessage(message);
        return true;
    }
    @RequestMapping("selectAll")
    public List<Message> slectAllMessage(){
        List<Message> res = messageService.selectAll();
        log.info(res.toString());
        return res;
    }
}
